package com.example.taskdemo.hanlder;

import android.util.Log;

import com.example.taskdemo.DataSingle;
import com.example.taskdemo.bean.PlayData;
import com.example.taskdemo.bean.PlayVideoData;
import com.example.taskdemo.tasks.BaseTask;

public class AIUILocalHandler {
    private AIUILocalHandler(){};
    private static AIUILocalHandler aiuiLocalHandler;
    public static synchronized AIUILocalHandler getInstance(){
        if(aiuiLocalHandler ==null){
            aiuiLocalHandler = new AIUILocalHandler();
        }
        return aiuiLocalHandler;
    }
    private final static String TAG = "AIUILocalHandler";
    public void broadcast(String string) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Log.d(TAG, "run: 开始播放！");
                    for(int i= 0; i<10; i++){
                        sleeptest(100,"播放"+string);
                        DataSingle.getInstance().UPPlayState(PlayData.PLAYState.PLAYING);
                    }
                    Log.d(TAG, "run: 播放完成！");
                    DataSingle.getInstance().UPPlayState(PlayData.PLAYState.FINISH);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    private void sleeptest(int millis,String info) throws InterruptedException {
        Thread.sleep(millis);
    }

    public void playVideo(String text) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Log.d(TAG, "run: 开始播放视频！");
                    for(int i= 0; i<10; i++){
                        sleeptest(100,"播放"+text);
                        DataSingle.getInstance().UPPlayViewState(PlayVideoData.PLAYVIDEOSTATE.PLAYING);
                    }
                    Log.d(TAG, "run: 视频播放完成！");
                    DataSingle.getInstance().UPPlayViewState(PlayVideoData.PLAYVIDEOSTATE.FINISH);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}

